package com.example.demo.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 会员实体
 */
@Data
@Entity
@Table(name = "members")
@EqualsAndHashCode(callSuper = true)
public class Member extends BaseEntity {
    
    @Column(name = "member_code", unique = true, nullable = false, length = 50)
    private String memberCode;
    
    @Column(name = "member_name", nullable = false, length = 50)
    private String memberName;
    
    @Column(name = "phone", length = 20)
    private String phone;
    
    @Column(name = "email", length = 100)
    private String email;
    
    @Column(name = "id_card", length = 20)
    private String idCard;
    
    @Column(name = "birth_date")
    private LocalDate birthDate;
    
    @Column(name = "gender", length = 10)
    private String gender;
    
    @Column(name = "address", length = 200)
    private String address;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "member_level", nullable = false)
    private MemberLevel memberLevel = MemberLevel.BRONZE;
    
    @Column(name = "total_points", nullable = false)
    private Integer totalPoints = 0;
    
    @Column(name = "available_points", nullable = false)
    private Integer availablePoints = 0;
    
    @Column(name = "total_consumption", precision = 10, scale = 2)
    private BigDecimal totalConsumption = BigDecimal.ZERO;
    
    @Column(name = "register_date", nullable = false)
    private LocalDate registerDate;
    
    @Column(name = "last_visit_date")
    private LocalDate lastVisitDate;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private MemberStatus status = MemberStatus.ACTIVE;
    
    /**
     * 会员等级枚举
     */
    public enum MemberLevel {
        BRONZE("青铜会员"),
        SILVER("白银会员"),
        GOLD("黄金会员"),
        PLATINUM("铂金会员"),
        DIAMOND("钻石会员");
        
        private final String description;
        
        MemberLevel(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 会员状态枚举
     */
    public enum MemberStatus {
        ACTIVE("正常"),
        INACTIVE("停用"),
        FROZEN("冻结");
        
        private final String description;
        
        MemberStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
}
